package be.redo.model.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * @author Frank Plain old Java class to represent a database table row.
 *         Represents a vacation in the domain model. It holds:
 *         <ul>
 *         <li>a set of flight reservations</li>
 *         <li>a set of stays</li>
 *         <li>a set of discounts</li>
 *         </ul>
 */
@Entity
@NamedQueries({
		@NamedQuery(name = "findAantalVacations", query = "select count(v) from Vacation v"),
		@NamedQuery(name = "findAllVacations", query = "select v from Vacation v order by v.customer"),
		@NamedQuery(name = "findVacationsByCustomer", query = "select v from Vacation v where v.customer = :customer"),
		@NamedQuery(name = "findVacationsByRegistrationEmployee", query = "select v from Vacation v where v.registrationEmployee = :employee") })
public class Vacation implements Serializable {

	/**
	 * Generated serialVersionUID.
	 */
	private static final long serialVersionUID = -7587846709619509918L;

	// /**
	// * Set of the flight reservations.
	// */
	// @NotNull
	// @OneToMany(cascade = CascadeType.ALL, mappedBy = "vacation")
	// private Set<Reservation> reservations = new HashSet<Reservation>();

	// /**
	// * Set of the stays.
	// */
	// @NotNull
	// @OneToMany(cascade = CascadeType.ALL, mappedBy = "vacation")
	// private Set<Stay> stays = new HashSet<Stay>();

	// /**
	// * Set if the discounts.
	// */
	// @NotNull
	// @OneToMany(cascade = CascadeType.ALL, mappedBy = "vacation")
	// private Set<Discount> discounts = new HashSet<Discount>();

	/**
	 * Customer that books the vacation.
	 */
	@NotNull
	@ManyToOne
	@JoinColumn(name = "customer")
	private Customer customer;

	@ManyToOne
	@JoinColumn(name = "registration_employee")
	private Employee registrationEmployee;

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

	// public Set<Reservation> getReservations() {
	// return this.reservations;
	// }

	// public void setReservations(Set<Reservation> reservations) {
	// this.reservations = reservations;
	// }

	// public Set<Stay> getStays() {
	// return this.stays;
	// }

	// public void setStays(Set<Stay> stays) {
	// this.stays = stays;
	// }

	// public Set<Discount> getDiscounts() {
	// return this.discounts;
	// }

	// public void setDiscounts(Set<Discount> discounts) {
	// this.discounts = discounts;
	// }

	public Customer getCustomer() {
		return this.customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Employee getRegistrationEmployee() {
		return this.registrationEmployee;
	}

	public void setRegistrationEmployee(Employee registrationEmployee) {
		this.registrationEmployee = registrationEmployee;
	}

	/**
	 * Generated key by the Database
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "vacation_id")
	private Long VacationId;

	public Long getVacationId() {
		return this.VacationId;
	}

	public void setVacationId(Long id) {
		this.VacationId = id;
	}

	/**
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((customer == null) ? 0 : customer.hashCode());
		// result = prime * result
		// + ((discounts == null) ? 0 : discounts.hashCode());
		result = prime
				* result
				+ ((registrationEmployee == null) ? 0 : registrationEmployee
						.hashCode());
		// result = prime * result
		// + ((reservations == null) ? 0 : reservations.hashCode());
		// result = prime * result + ((stays == null) ? 0 : stays.hashCode());
		return result;
	}

	/**
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Vacation other = (Vacation) obj;
		if (customer == null) {
			if (other.customer != null) {
				return false;
			}
		} else if (!customer.equals(other.customer)) {
			return false;
		}
		// if (discounts == null) {
		// if (other.discounts != null) {
		// return false;
		// }
		// } else if (!discounts.equals(other.discounts)) {
		// return false;
		// }
		if (registrationEmployee == null) {
			if (other.registrationEmployee != null) {
				return false;
			}
		} else if (!registrationEmployee.equals(other.registrationEmployee)) {
			return false;
		}
		// if (reservations == null) {
		// if (other.reservations != null) {
		// return false;
		// }
		// } else if (!reservations.equals(other.reservations)) {
		// return false;
		// }
		// if (stays == null) {
		// if (other.stays != null) {
		// return false;
		// }
		// } else if (!stays.equals(other.stays)) {
		// return false;
		// }
		return true;
	}

}
